Today, I'm going to show you something called the Binder Bull event.
And it's a way you can send information from one script to another if they're of the same type.
So a server script to a server script, local script to a local script, and we'll go through the client
server stuff when we do remote events, which is coming up soon.
I'm going to demonstrate binding events by sending a message from my wave loop to my lava script, make
an eruption go off.
So it's going to be a server thing to a server thing, right?
Both are server scripts.
I'm going to go to server storage because this is going to be an event that's happening on the server
side.
I'm going to go to plus right here, hit a B for findable event and add it.
It doesn't have to be in server storage.
It could be in the workspace, but I'm going to put it here so I don't forget where it's at.
I'm going to call this lava B for lava bind double event.
Now I'm going to open up my wave loop, go to server script service, wave loop, and I'm going to get
access to my BIND event.
I put it in server storage, so I'm going to need a variable for that.
I'll call that s for server storage game, get service server storage.
And in there we have our bind able event and we call that larva B, I'll call the variable larva B but
with a lowercase L, that's just my convention and we'll get our server server storage variable, wait
for a child and then larva B make sure you see it in there.
All right.
Another variable I'm going to use is a wave loop counter.
So I'm just going to do local wave loop equals zero.
Let's go ahead and scroll down to the bottom of our while loop underneath the spawn zombies.
I'll do a little wait right here, maybe a second.
Just to slow down my loop and then I'm going to fire my bull event, my lava B, I'll do lava B colon
fire.
That's going to fire the event off.
We'll be able to pick that up in our lava script.
I'm going to show you in a minute.
But just to make it interesting, I'm going to send two values with my bondable event so you can see
how to transfer data.
I'll send two messages, maybe lava event with an exclamation so you could see it strings going over.
And then we're going to do our wave loop, right, just so you can see an integer going, too.
Let's go ahead and get our wave loop.
Do a plus equals one.
So we're going to increment our wave loop every iteration of the loop.
We're going to take the old wave loop and add one to it.
Now let's go ahead and look for our lava in the workspace.
Here's my workspace.
Here's lava.
I'm going to open it up and then open the eruption script.
There we go.
I need to get that findable event and listen to it.
So I'm going to make a variable for server storage right here at the top.
And I'll say.
That's my variable convention for server storage gain colon, Get service, server storage.
Then I'm going to get another variable for my binding event and I'm going to call Lava B because I don't
want to get confused.
I'm going to get that from server storage.
I'll do a wait for child lava B.
In this script.
Notice that we already have our erupt function and our drain function, but down here we only call it
one time.
We wait 8 seconds after the game starts up, erupt.
Wait a second drain.
Let's wrap this in a function so that we can call it periodically with our bondable event.
So I got rid of that.
Wait 8 seconds.
I don't need it.
I'm going to do a local function activate eruption.
I'm going to go down underneath the drain and do my end.
I'm wrapping this in a function called Activate eruption.
Let's go to format selection, format, document, give us some nice indents.
And remember, we are our able event.
We pass two parameters.
We can capture those here.
Let's get some variables for those parameters.
We'll say MSG because one said something like lava vent and then a val for our integer.
We had a wave loop coming over to and you can send more stuff than that.
I'm just showing you how to do it.
All right.
So we had our lava be that was the binding event.
We are going to listen for that event and connect to activate eruption.
Get rid of these extra two parentheses.
We don't need them through the magic of roadblocks.
It's going to know to pass those variables, but let's print those variables out since we're not really
using them, you really need to know if they're there or not.
Right.
So let's do a message equals MSG and then a val equals val.
Now that we print them out, you can see that they're there and you could use that data if you wanted
to.
We don't need it in this example, though.
All right, So before we test this, I'm going to go back to my wave loop and take a look at where we
fire that findable event.
Fire it down here.
But we do it every loop, iteration.
And those loops don't take very long, what, maybe 5 seconds plus a little more for some spawning.
I want to fire this every fifth loop iteration.
Well, I can do that because now I have a wave loop counter and I can put an F statement in here.
I'm going to say if wave loop modulo five equals equals zero, then I'm going to fire my event.
Right?
So what we're doing is we are seeing if we divide wave loop by five and there's a zero remainder, then
we're going to consider that if statement true and fire the loop.
So it's only going to fire on zero and five and ten like that.
Let's try it out.
All right.
So now let's go to the View output and we're going to check for errors.
I will run on over.
I'm going to get rid of that surface terrain print out that's kind of messing up my output window.
Let's listen for our eruption and check for our message.
Here we go.
There's our message.
Message Lava event value zero.
So that was the first, the zero wavelength.
And then it won't go again until we hit number five.
I should pause that.
Maybe I'll zap some zombies while we're waiting here.
Here we go.
And there we are.
Message Larva Event Value five o The Zombies Getting.
So it looks like we got a nice a nice binder bull event firing off or a lava eruption periodically.